Repository navigation
check for pseudo header in trailer - #305
Conversation
|
Hrm, right now I can't see what is going wrong because I'm flying and have no access to a proper shell (I'm on a phone in an airport), and Travis is failing the build on the linter. I'll follow this up tomorrow. |
48f897e to
966fb96
Compare
|
Sorry, I was expecting the test to fail so I didn't check the reason. It's now failing by NOT raising the |
I had a proper look, and it’s because the functionality isn’t implemented yet. So you’ll need to add it – if you look in Looking at the test already written: looks fine to me (but I’m far from an HTTP/2 expert), but you should also check that we send the appropriate response (with an HTTP error code) back down the connection. If you look at |
| c.clear_outbound_data_buffer() | ||
|
|
||
| head_flag = ["END_HEADERS"] | ||
| stream_flag = ["END_STREAM"] |
There was a problem hiding this comment.
There's no reason for us to hoist these out, they can go straight into the relevant frame factory calls.
|
Thanks for clarifying that @alexwlchan! @Lukasa, sorry about all the junk, I didn't intend to have this reviewed yet. I just wanted to clarify that the test was working as intended before extending. I'll start working on getting that exception raised :) |
|
@Lukasa, it looks like this test in test_complex_logic.py may need some tweaks. It is currently sending two sets of headers, both with a Some possible solutions are sending a different header set (sans pseudo-headers), or just a data frame. This may need some more investigating if I'm missing something deeper though. edit: I realized that the outbound send is for a promise frame rather than a header frame. I'm not sure what the semantics of the promise frame are, but that's probably the reason why we're not getting an error on the outbound. |
|
Are there different rules from inbound v.s. outbound header frames? |
|
A PUSH_PROMISE frame contains request headers, not response headers. Essentially, the server pushes a request and then sends its own response to it. |
No, there aren't. However, some of the checks on inbound header frames don't apply to outbound headers because we normalize them first. There's no point checking for whitespace or uppercase header fields because we got rid of any violations already. |
|
Ok cool, thanks @Lukasa. Is that second header frame supposed to be treated as a new response, or a trailer? I'll need to tweak it, or my validation check to get tests passing. |
|
There is only one HEADERS frame. =) It is, therefore, not a trailer. |
fa28998 to
61106a2
Compare
| ] | ||
| assert headers == h2.utilities.validate_headers( | ||
| headers, hdr_validation_flags) | ||
| if not hdr_validation_flags.is_trailer: |
There was a problem hiding this comment.
This fixes the failure condition but raises a question of if we really want to use hdr_validation_combos with this test. This will never be a valid trailer header and we're now checking for trailers with pseudo headers elsewhere, so this seems a bit redundant.
If this is a special case that requires all the checks though, I like this over a blanket try/except ProtocolError catch since this should be the only condition we fail under.
There was a problem hiding this comment.
I think you just want to add a new set of header validation combos that doesn't include the trailer set, and use that here.
|
Ok, after some further reading, I'm fairly confident the |
b44d9ab to
a09e16f
Compare
| headers=self.example_response_headers, | ||
| data=b'the content', | ||
| flags=['END_STREAM'], | ||
| ) |
There was a problem hiding this comment.
Ok, seeing this change in place I now understand what you were getting at. Yes, there is nothing wrong with closing that stream using trailers, but the trailers that were being sent were not actually valid trailers. This change is better. =)
5069db1 to
af26031
Compare
|
Alright, I think things are tidied. Gonna call it a night but I'll finish off any final tweaks in the morning. |
| if hdr_validation_flags.is_trailer and seen_pseudo_header_fields: | ||
| raise ProtocolError( | ||
| "Received pseudo-header in trailer %s" % | ||
| seen_pseudo_header_fields.pop() |
There was a problem hiding this comment.
Eh, let's just show them all. We can just show the set directly. =)
af26031 to
1327ed9
Compare
|
Voilà! |
|
Alright, fantastic, thanks so much @nateprewitt! Per our one of the team policy, you've got an invite to the Python Hyper organisation in your inbox. Welcome on board! |
So, I'm quickly realizing that I'm way out of my element here with HTTP2, so please excuse my naivety.
From the quick reading I did, I think this workflow should fail with a
ProtocolError, but currently doesn't. I'm not sure how state works with the connection object here, so it's possible I'm not using the frames correctly.@Lukasa or @alexwlchan, could I get some confirmation that this is along the right path?